<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class User_model extends CI_Model {

    public function getUserLogin($param) {
        $data['username'] = $param['username'];
        $data['password'] = $param['password'];
        $data['status'] = '1';

        $query = $this->db->get_where('users', $data);
        $result = $query->result_array();
        if ($result)
            return $result[0];
        else
            return false;
    }

    public function getUser() {
        $query = $this->db->get('users', 10);
        return $query->result_array();
    }

    public function getUserById($id) {
        $query = $this->db->get_where('users', array('id' => $id), 1);
        $result = $query->result_array();
        return $result[0];
    }

    public function updateUserById($param) {
        $id = $param['id'];
        $data = array(
            'username' => $param['username'],
            'password' => $param['password'],
            'status' => $param['status'],
            'modified' => date('Y-m-d H:i:s')
        );
        $this->db->where('id', $id);
        return $this->db->update('users', $data);
    }

    public function insertUser($param) {
        $data = array(
            'username' => $param['username'],
            'password' => $param['password'],
            'status' => $param['status'],
            'created' => date('Y-m-d H:i:s')
        );

        return $this->db->insert('users', $data);
    }

    public function deleteUserById($id) {
        return $this->db->delete('users', array('id' => $id));
    }

}